package com.chen.gulimall.gulimallproduct.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;

import com.chen.gulimall.gulimallproduct.service.AttrService;
import com.chen.gulimall.gulimallproduct.vo.AttrRespVo;
import com.chen.gulimall.gulimallproduct.vo.AttrVo;
import com.chen.gulimallcommon.common.utils.PageUtils;
import com.chen.gulimallcommon.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品属性
 *
 * @author mr.chen
 * @email 3061634906@qq.com
 * @date 2022-04-19 17:30:10
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("gulimallproduct:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    @GetMapping("/{attrType}/list/{catelogId}")
    public R getBaseList(@RequestParam Map<String,Object> params,@PathVariable("catelogId") Long catelongId,@PathVariable("attrType") String type) {
        PageUtils page = attrService.queryBaseList(params,catelongId,type);

        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{attrId}")
    //@RequiresPermissions("gulimallproduct:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrRespVo attr = attrService.getAttrId(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("gulimallproduct:attr:save")
    public R save(@RequestBody AttrVo attrVo){
		attrService.saveAttrVo(attrVo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("gulimallproduct:attr:update")
    public R update(@RequestBody AttrRespVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("gulimallproduct:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
